use actix_web::Error;
use actix_web::web::{Json, Path};
use apistos::actix::CreatedJson;
use apistos::api_operation;
use uuid::Uuid;

use crate::domains::params::CreateTodoParam;
use crate::domains::views::ToDoDetailVO;

#[api_operation(summary = "Get an element from the todo list")]
pub(crate) async fn get_todo(todo_id: Path<Uuid>) -> Result<Json<ToDoDetailVO>, Error> {
    Ok(Json(ToDoDetailVO {
        id: todo_id.into_inner(),
        title: "some title".to_string(),
        description: None,
    }))
}

#[api_operation(summary = "Add a new element to the todo list")]
pub(crate) async fn create_todo(
    body: Json<CreateTodoParam>,
) -> Result<CreatedJson<ToDoDetailVO>, Error> {
    let param: CreateTodoParam = body.into_inner();
    let vo = ToDoDetailVO {
        id: Uuid::new_v4(),
        title: param.title,
        description: Some(param.description),
    };
    Ok(CreatedJson(vo))
}
